<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>雪碧图播放</title>
    <script src="../dist/anikyu.js"></script>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            background-color: #fff;
            position: relative;
        }

        .target {
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            margin: auto;
            width: 256px;
            height: 256px;
            background-image: url(./_res/css_sprites.png);
        }
    </style>
</head>

<body>
    <div class="target" id="target"></div>
    <script>
        var el = document.getElementById('target')

        var obj = {}

        var imgH = 25600, step = 99
        var singleH = imgH / (1 + step)

        var ani = new Anikyu(obj, [
            {
                props: {
                    top: 0
                }
            },
            {
                easeType: 'step',
                step: step,
                delay: 0,
                duration: 3000,
                props: {
                    top: - (imgH - singleH)
                }
            },
            {
                easeType: 'step',
                step: 33,
                delay: 0,
                duration: 1000,
                props: {
                    top: 0
                }
            },
        ], {
            easeType: 'elasticInOut'
        })
        ani.addEventListener('animate', function (e) {
            el.style.backgroundPositionY = e.detail.value.top + 'px'
        })
        ani.addEventListener('finish', function (e) {
            if (e.detail.stageIndex === 2) {
                ani.jump(0)
            }
        })

    </script>
</body>

</html>